<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>在线调试</title>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="/3nod_web/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/3nod_web/layui/css/soulTable.css" media="all"/>
</head>
<body>
<table id="myTable"></table>
<script type="text/html" id="toolbar">
    <div>
        <button class="layui-btn layui-btn-sm" lay-event="clearFilter">清除所有筛选条件</button>
    </div>
</script>
<script src="/3nod_web/layui/layui.js" charset="utf-8"></script>
<script>
    // 自定义模块
    layui.config({
        base: '/3nod_web/layui/ext/',   // 模块目录
        version: 'v1.4.4'
    }).extend({             // 模块别名
        soulTable: 'soulTable'
    });


    layui.use(['form', 'table', 'soulTable'], function () {
        var table = layui.table,
            soulTable = layui.soulTable;

        // 后台分页
        table.render({
            elem: '#myTable'
            , id: 'myTable'
            , url: '/3nod_web/iqcDetection/list/'
            , cellMinWidth: 0
            , toolbar: '#toolbar'
            , cols: [
                [
                    {checkbox: true, fixed: true}
                    , {field: 'receiptKey', title: 'ASN/收货单', fixed: true, width: 150, filter: true}
                    , {field: 'extReceiptForm', title: '送货单', width: 170, filter: true}
                    , {field: 'shipper', title: '货主', width: 80, filter: true}
                    , {field: 'sku', title: '物料编码', width: 115, filter: true}
                    , {field: 'materialDesc', title: '物料描述', width: 115, filter: true}
                    , {field: 'inspectionCategoryDesc', title: '检验类别', width: 115, filter: true}
                    , {field: 'supplierKey', title: '供应商代码', width: 115, filter: true}
                    , {field: 'supplierName', title: '供应商名称', width: 115, filter: true}
                    , {field: 'receivedQty', title: '接收量', width: 115, filter: true}
                    , {field: 'receiveTime', title: '收货时间', width: 115, filter: true}
                    , {field: 'qualityStatus', title: '质检状态', width: 115, filter: true}
                    , {field: 'loc', title: '储位', width: 115, filter: true}
                    , {field: 'remark', title: '备注', width: 115, filter: true}
                ]
            ]
            , page: true
            , limits: [20, 50, 100, 200, 500, 1000, 2000, 3000, 4000, 5000]
            , limit: 20
            , height: 'full-110'
            , done: function () {
                soulTable.render(this)
                //分类显示中文名称
                $("[data-field='qualityStatus']").children().each(function () {
                    if ($(this).text() == '1') {
                        $(this).text("待检")
                    } else if ($(this).text() == '2') {
                        $(this).text("质检中")
                    } else if ($(this).text() == '3') {
                        $(this).text("已完成")
                    }
                })
            }
        });

        table.on('toolbar(myTable)', function (obj) {
            if (obj.event === 'clearFilter') {
                // 清除所有筛选条件并重载表格
                // 参数: tableId
                soulTable.clearFilter('myTable')
            }
        });
        var $ = layui.$, active = {
            reload: function () {
                var receiptKey = $('#receiptKey');
                var shipper = $('#shipper');
                var sku = $('#sku');
                var supplierKey = $('#supplierKey');
                var supplierName = $('#supplierName');
                var extReceiptForm = $('#extReceiptForm');
                var receivedQty = $('#receivedQty');
                var receiveTime = $('#receiveTime');
                var qualityStatus = $('#qualityStatus');
                var loc = $('#loc');
                var remark = $('#remark');

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        receiptKey: receiptKey.val(),
                        shipper: shipper.val(),
                        sku: sku.val(),
                        supplierKey: supplierKey.val(),
                        supplierName: supplierName.val(),
                        extReceiptForm: extReceiptForm.val(),
                        receivedQty: receivedQty.val(),
                        receiveTime: receiveTime.val(),
                        qualityStatus: qualityStatus.val(),
                        loc: loc.val(),
                        remark: remark.val(),
                    }
                }, 'data');
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            console.log(type)
            active[type] ? active[type].call(this) : '';
        });
    })
</script>
</body>
</html>
